package com.weixin.paleituo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.bean.LevelsBean;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.MyGridView;

import java.util.List;

/**
 * Author yichao
 * Time  2017/12/1 0:38
 * Dest  租房子
 */

public class LeaseHouseContentRecyclerViewAdapter extends RecyclerView.Adapter<LeaseHouseContentRecyclerViewAdapter.ViewHolder> {
    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    private int roomId=-1;

    private Context mContext;
    private List<LevelsBean> mLevelsBeanList;

    public LeaseHouseContentRecyclerViewAdapter(Context context, List<LevelsBean> levelsBeanList) {
        mContext = context;
        mLevelsBeanList = levelsBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= UIUtils.inflate(mContext,R.layout.sale_status_content_item_layout,parent,false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder,final int position) {

        LeaseHouseContentGridViewAdapter leaseHouseContentGridViewAdapter=new LeaseHouseContentGridViewAdapter(mContext,mLevelsBeanList.get(position).getRooms(),roomId);
        holder.mMyGridView.setAdapter(leaseHouseContentGridViewAdapter);
        holder.mTextView.setText(mLevelsBeanList.get(position).getLevel()+"F");

if (mOnItemClickListener!=null){
    holder.mItemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mOnItemClickListener.onClick(v,position);
        }
    });

}
    }

    @Override
    public int getItemCount() {
        return mLevelsBeanList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private View mItemView;
        private TextView mTextView;

        private final MyGridView mMyGridView;

        public ViewHolder(View itemView) {
            super(itemView);
            mItemView = itemView;
          //  mFlowLayout= mItemView.findViewById(R.id.flowlayout_sale_status_menu);
            mMyGridView = mItemView.findViewById(R.id.gridView_sale_status_menu);
            mTextView=   mItemView.findViewById(R.id.tv_title_sale_statues_content_item_layout);


        }
    }
private OnItemClickListener mOnItemClickListener;
    public interface OnItemClickListener{
      public   void onClick(View v, int position);

    }
public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener=onItemClickListener;

}

}
